
var DetectSquares = function() {
  this.mapX = new Map()
  this.mapY = new Map()
  this.pset = new Set()
};

/** 
 * @param {number[]} point
 * @return {void}
 */
DetectSquares.prototype.add = function(point) {
  const { mapX, mapY, pset } = this
  const [x, y] =  point
  if(!mapX.has(x)){
    mapX.set(x, [])
  }
  if(!mapY.has(y)){
    mapY.set(y, [])
  }
  mapX.get(x).push(y)
  mapY.get(y).push(x)
  pset.add(point.toString())
};

/** 
 * @param {number[]} point
 * @return {number}
 */
DetectSquares.prototype.count = function(point) {
  const { mapX, mapY, pset } = this
  const [x, y] = point
  const arrY = mapX.get(x) || []
  const arrX = mapY.get(y) || []
  let cnt = 0
  for(const xx of arrX){
    if(xx === x){
      continue
    }
    for(const yy of arrY){
      if(yy === y){
        continue
      }
      if( Math.abs(x - xx) !== Math.abs(y - yy)){
        continue
      }
      if(pset.has([xx,yy].toString())){
        cnt++
      }
    }
  }
  return cnt
};

/**
 * Your DetectSquares object will be instantiated and called as such:
 * var obj = new DetectSquares()
 * obj.add(point)
 * var param_2 = obj.count(point)
 */